package com.ross.springboot.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ross.springboot.entity.Resources;
import com.ross.springboot.mapper.ResourcesMapper;
import com.ross.springboot.service.IResourcesService;
import com.ross.springboot.service.impl.BaseService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ross
 * @since 2020-07-24
 */
@Service
public class ResourcesServiceImpl extends BaseService<Resources> implements IResourcesService {

    @Resource
    private ResourcesMapper resourcesMapper;

    @Override
    public PageInfo<Resources> selectByPage(Resources resources, int start, int length) {
        Integer page = start/length+1;
        Example example = new Example(Resources.class);
        //分页查询
        PageHelper.startPage(page,length);
        List<Resources> resourcesList = selectByExample(example);
        return new PageInfo<>(resourcesList);
    }

    @Override
    public List<Resources> queryAll() {
        return this.resourcesMapper.queryAll();
    }

    @Override
    public List<Resources> loadUserResources(Map<String, Object> map) {
        return this.resourcesMapper.loadUserResources(map);
    }

    @Override
    public List<Resources> queryResourcesListWithSelected(Integer rid) {
        return this.resourcesMapper.queryResourcesListWithSelected(rid);
    }
}
